%calcVDWV will calculate the van de Waals volume of an amino acid sequence
%in A^3 units.
%
%  VDWV = calcVDWV(Seq)
%
%  Info = calcVDWV
%
%  INPUT
%    Seq: string or cell of string of amino acid sequences
%         *If empty, will return the Info structure
%
%  OUTPUT
%    VDWV: value or matrix of VDWV values
%    Info: structure of VDWV data
%
%  REFERENCE
%  http://www.proteinsandproteomics.org/content/free/tables_1/table08.pdf

function VDWV = calcVDWV(Seq)
Info =  {...
    'A',   67; ...
    'R',  148; ...
    'N',   96; ...
    'D',   91; ...
    'C',   86; ...
    'Q',  114; ...
    'E',  109; ...
    'G',   48; ...
    'H',  118; ...
    'I',  124; ...
    'L',  124; ...
    'K',  135; ...
    'M',  124; ...
    'F',  135; ...
    'P',   90; ...
    'S',   73; ...
    'T',   93; ...
    'W',  163; ...
    'Y',  141; ...
    'V',  105; ...
    };
if nargin == 0
    VDWV = Info;
    return
end

AAVDWV = cell2mat(Info(:, 2)); %amino acid mw

if iscell(Seq)
    VDWV = zeros(size(Seq));
    for j = 1:numel(Seq)
        VDWV(j) = sum(AAVDWV .* countAA(Seq{j}, Info));
    end
else
    VDWV = sum(AAVDWV .* countAA(Seq, Info));
end

function C = countAA(Seq, Info)
Seq = upper(Seq);
C = cellfun(@(x) sum(Seq == x), Info(:, 1));